import React,{useContext, useState} from 'react';
import './style.css';
import {ContextComponent} from '../../index.js';


export default function Tlhead() {

    const [val,setVal] = useState('');
    const {dispatch} = useContext(ContextComponent);

    
    function updateVal(e) {
        
        setVal(e.target.value);
    }

    function addList(e) {

        if (e.keyCode == 13){
            dispatch({
                type:'ADD',
                value:e.target.value
            })

            setVal('');
        }
        
    }



    return (
        <div className="">
            
            <input type="text" value={val} onChange={updateVal} onKeyDown={addList} placeholder="请输入待办事件"/>
        
        </div>
    )
}